<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <a-card>
      <div class="table-page-search-wrapper">
        <title-name title="设计资料信息" />
        <a-form-model
          ref="form1"
          layout="horizontal"
          :model="form"
          :rules="rules"
        >
          <a-row :gutter="24">
            <a-col
              :md="16"
              :sm="16"
            >
              <a-form-model-item
                label="所属单位"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="branchId"
              >
                <BaseInput
                  v-model="form.viewName"
                  disabled
                  placeholder=""
                />
              </a-form-model-item>
            </a-col>
            <!--            <a-col-->
            <!--              :md="8"-->
            <!--              :sm="8"-->
            <!--            >-->
            <!--              <a-form-model-item-->
            <!--                label="项目名称"-->
            <!--                :label-col="{lg: {span:7}, sm: {span:7}}"-->
            <!--                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"-->
            <!--                prop="projectId"-->
            <!--              >-->
            <!--                <SelectProject-->
            <!--                  v-model="form.projectId"-->
            <!--                  disabled-->
            <!--                  placeholder="请选择"-->
            <!--                  :form="form"-->
            <!--                  :is-clear="isEdit==0"-->
            <!--                  key-value="branchId"-->
            <!--                  @change="getPojectDetails(form.projectId)"-->
            <!--                />-->
            <!--              </a-form-model-item>-->
            <!--            </a-col>-->
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="项目设计管理类别"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
              >
                <BaseInput
                  v-model="form.projectType"
                  disabled
                  placeholder=""
                />
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="设计资料名称"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="resultName"
              >
                <BaseInput
                  v-model="form.resultName"
                  disabled
                  placeholder=""
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="设计资料类型"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="resultTypeId"
              >
                <a-select
                  v-model="form.resultTypeId"
                  disabled
                >
                  <a-select-option
                    v-for="item in resultTypes"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="图纸版本号"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="versionNum"
              >
                <BaseInput
                  v-model="form.versionNum"
                  disabled
                  placeholder=""
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="出图时间"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="drawTime"
              >
                <a-date-picker
                  v-model="form.drawTime"
                  disabled
                  style="width:100%"
                  @change="onChangeTime"
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="设计单位名称"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
                prop="designUnit"
              >
                <BaseInput
                  v-model="form.designUnit"
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="创建人"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
              >
                <BaseInput
                  v-model="form.creator"
                  disabled
                  placeholder=""
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="创建时间"
                :label-col="{lg: {span:7}, sm: {span:7}}"
                :wrapper-col="{lg: {span: 17}, sm: {span: 17} }"
              >
                <BaseInput
                  v-model="form.createdTime"
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item
                label="设计资料概述"
                :label-col="{lg: {span:2}, sm: {span:2}}"
                :wrapper-col="{lg: {span: 22}, sm: {span: 22} }"
              >
                <editor
                  v-model="form.resultInfo"
                  disabled
                  :is-clear="true"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>

        <title-name title="设计资料相关资料上传" />
        <u-table
          :upload-arrys="uploadArrys"
          :list-url="listUrl"
          :is-show="false"
          :upload-list="uploadList"
          :business-id="businessId"
          :delete-url="deleteUrl"
          business-code="PM16"
          @fileArrysData="fileArrysData"
        />
      </div>
    </a-card>

    <div v-if="!isConsultation" class="page-btn-right-top">
      <!-- <div style="float:right;margin-top: 20px"> -->
      <a-button
        type="primary"
        @click="goBack"
      >
        关闭
      </a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
  import {  getDesignResourcesList } from '@/api/design/parameter'
  import { getTypes } from '@/api/commons'
  import { addDesignResult, getDesignDetails, editDesignResult,getTypeLabels } from '@/api/project/designResult'
  import { getProjectBranchType  } from '@/api/project/designChange'

  import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
  import SelectProject from '@/components/Select/SelectProject' // 项目
  import editor from '@/components/Editor/editor';

  import ARow from 'ant-design-vue/es/grid/Row'

  const columns = [
    {
      title: '序号',
       width: 65,
      dataIndex: 'serial',

      scopedSlots: { customRender: 'serial' },
    },
    {
      title: '设计资源名称',
      dataIndex: 'name',
      width: '20%',
    },
    {
      title: '设计资源类型',
      dataIndex: 'type',
      width: '30%',
    },
    {
      title: '设计资源等级',
      dataIndex: 'level',
      width: '30%',
    }
  ];


  export default {
    name:'a'+Date.now(),
    components: {
      ARow,
      editor,
      SelectSubCompany,
      SelectProject
    },
    props: {
      // 是否作为审批详情
      isAudit: {
        type: Boolean,
        default: false
      },
      // 是否作为意见征询
      isConsultation: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        columns,
        uploadArrys:[],
        pageNo:1,
        pageSize:10,
        totalSize:0,
        tableData:[],
        searchArr: [
          // 搜索框
          {
            name: '设计资源名称',
            value: 'designResourceName',
            type: 'input'
          },
          {
            name: '设计资源类型',
            value: 'resTypeId',
            type: 'select',
            data:[]
          },
          {
            name: '设计资源等级',
            value: 'resLevelId',
            type: 'select',
            data:[]
          },
        ],

        // 资料上传
        listUrl:'',
        deleteUrl:'/cscec-project-business/file/business/project-fileDelete',
        uploadList:'/cscec-project-business/file/business/fileUpload',
        businessId:'',

        data:[],
        resultTypes:[],  //  设计资料类型
        visible:false,
        title:'选择设计资源',

        form:{
          creator:'',
          projectType:'',
          viewName: ""
        },
        currentDate:'', // 当前日期

        selectedRowKeys: [],
        selectedRows: [],

        isEdit:'',
        id:'',

        companys:[],
        projectNames:[],

        type:'',
        rules: {}

      }
    },

    created() {

      this.id = this.$route.query.id
      this.isEdit = this.$route.query.isEdit
      this.type = this.$route.query.type

      this.getTypes()

        this.getDesignDetails()

        this.getCurrentDate()  // 获取当前日期
        this.getTypeLabels()  // 获取当前日期
    },
    computed: {
      rowSelection(){
        return {
          selectedRowKeys : this.selectedRowKeys ,
          selectedRows : this.selectedRows ,   // 当前行所有数据
        }
      },
    },
    methods: {
      getTypes(){
        getTypes({type:13}).then(res=>{
          this.searchArr[2].data = this.getChangeDatatTypes(res.data)
        })

        getTypes({type:14}).then(res=>{
          this.searchArr[1].data = this.getChangeDatatTypes(res.data)
        })
      },
      fileArrysData(val){
        this.form.fileList = val
      },
      getCurrentDate(){
        var d1 = new Date()
        var year = d1.getFullYear();//年
        var month = d1.getMonth() + 1;//月
        var day = d1.getDate();//日

        if (month < 10) {
          month = "0" + month;
        }
        if (day < 10) {
          day = "0" + day;
        }
        this.currentDate = year + "-"+month+"-"+day

      },
      handlePageChange(pageNo, pageSize) {
        this.pageNo = pageNo;
        this.getDesignResourcesList()
      },
      showSizeChange(pageNo, pageSize) {
        this.pageNo = 1;
        this.pageSize = pageSize;
        this.getDesignResourcesList()
      },

      getDesignResourcesList:function (params) {
        let searchData = Object.assign({pageSize: this.pageSize, pageNo: this.pageNo}, params);
        getDesignResourcesList(searchData).then(res => {
          if (res.code == 200) {
            this.tableData = res.data;
            this.totalSize = res.totalSize;
          }
        })
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        // form.designUnit

        this.form.designUnit = selectedRows[0].name
        this.form.designUnitId = selectedRows[0].id
        this.selectRow = selectedRows[0];
        this.selectedRowKeys = selectedRowKeys;
      },

      searchDatas(val) {
        this.pageNo = 1;
        this.getDesignResourcesList(val);
      },

      getTypeLabels(){
        getTypeLabels({type:21}).then(res=>{
          if(res.code == 200){
            this.resultTypes = res.data
          }
        })
      },



      goBack(){
        if(this.type == 'approve'){
          window.close()
        }else {
          this.$multiTab.close(this.$route.fullpath)
        }
      },


      getDesignDetails(){
        getDesignDetails({id:this.id}).then(res=>{
          this.$nextTick(()=>{
            this.form = res.data
            this.form.viewName = this.form.branch + '/' + this.form.project
            this.uploadArrys = this.form.fileList
          })
        })
      },

      changeData(){
          this.visible = true
      },

      handleCancel(){
        this.visible = false
      },

      handleOk(){
        this.visible = false
      },

      onChangeTime(val){
        this.form.drawTime = val.format('YYYY-MM-DD')
      },
    }
  }
</script>
